<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Paojiao
 *
 * @author dragon.hu add @2016.2.26
 */
require_once 'BaseChannel.php';

//泡椒
class Paojiao implements BaseChannel 
{
	
	function __construct() 
	{
		//echo "construct";
	}

	//put your code here
	function android($data) 
	{
		$paymentKey="Ze4NIXQFOmdO3OMbHF6jx02w0OhXFN9u"; //serverSecret
		$ret = $this->paymentCallBack($paymentKey, ANDROID);
		echo $ret;
	}

	function ios($data) 
	{
		$paymentKey=""; //
		$ret = $this->paymentCallBack($paymentKey, IOS);
		echo $ret;
	}

	function paymentCallBack($paymentKey, $platform)
	{
		$orderLog = new ChargeOrder();
		
		$orderLog->log("paojiao", $_REQUEST);
		
		$uid = $_REQUEST['uid'];
		$orderNo = $_REQUEST['orderNo'];
		$price = $_REQUEST['price'];
		$status = $_REQUEST['status'];
		$remark = $_REQUEST['remark'];
		$subject = $_REQUEST['subject'];
		$gameId = $_REQUEST['gameId'];
		$payTime = $_REQUEST['payTime'];
		$ext = $_REQUEST['ext'];
		$sign = $_REQUEST['sign'];
		
		$mysign = "uid=".$uid."price=".$price."orderNo=".$orderNo."remark=".$remark."status=".$status.
		"subject=".$subject."gameId=".$gameId."payTime=".$payTime."ext=".$ext;
		$mysign .= $paymentKey;
		
		if($sign == md5($mysign))  
		{ //验证通过
			 $tmpstatus = STATUS_SUCCESS;
			 if ($status != 5)
			 {
			 	$tmpstatus = STATUS_FAILD;
			 }
			//进行发货
			if(false == $orderLog->recordOrder($tmpstatus, $price, $ext, "paojiao", $platform,$orderNo))
			{
				$ret = "fail";
				$orderLog->log("paojiao",array("order"=>$ext,"money"=>$price,"serverresult"=>"faild"));
			}else 
			{
				//支付成功
				$ret="success";
				$orderLog->log("paojiao",array("order"=>$ext,"money"=>$price,"serverresult"=>"success"));
			}
		} 
		else 
		{
			//"$sig验证失败"
			$ret = "fail";
			$orderLog->log("paojiao","  order:$ext  sign error sign:$sign mysign:$mysign");
		}
		return $ret;
	}
	
}